<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>学籍修改-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<script src="<%=basePath %>/js/picker.js"></script>
<script src="<%=basePath %>/js/select.js"></script>
<script src="<%=basePath %>/js/picker-city.js"></script>
</head>
<body ontouchstart>
	
	<div class="weui_tab tab-bottom">
		<div class="weui-header bg-blue"> 
	  		<div class="weui-header-left"> <a onclick="back()" href="javascript:" class="icon icon-109 f-white">返回</a> </div>
	    	<h1 class="weui-header-title">学生信息变更</h1>
	    	<div class="weui-header-right" id="studentSubmit"><a href="javascript:void(0);" class="weui_btn weui_btn_mini weui_btn_primary bg-green">保存</a></div>
	    </div>
		<div class="weui_tab_bd">
	        <div class="weui_cells" style="margin-top: 0;">
	        	<input type="hidden" id="id" name="id" value="${student.id }"/>
	            <div class="weui_cell">
	                <div class="weui_cell_hd" style="position: relative;margin-right: 15px;">
	                    <img class="circle bg-blue-b" src="<%=basePath %>/images/default.jpg" style="width: 50px;display: block">
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input" name="name" id="name" value="${student.name }"></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">班级</label>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" type="text" value="${student.gradeName }（${student.clazz }）班" readonly/></div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">性别</label>
	                </div>
	                <div class="weui_cell_ft"><input type="text" class="weui_input tleft" name="sex" id="sex" value="${student.sex }" readonly="readonly"/></div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">身份证件类型</label>
	                </div>
	                <div class="weui_cell_ft"><input type="text" class="weui_input tleft" name="idNoType" id="idNoType" value="${student.idNoType }" placeholder="请选择" /></div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">身份证号码</label>
	                </div>
	                <div class="weui_cell_ft"><input type="text" class="weui_input tleft" name="idNo" id="idNo" value="${student.idNo }" /></div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">出生日期</label>
	                </div>
	                <div class="weui_cell_ft">
	                	<input type="text" class="weui_input tleft" name="birthday" id="birthday" value="<fmt:formatDate pattern='yyyy-MM-dd' value='${student.birthday}' />" />
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">出生地</label>
	                </div>
	                <div class="weui_cell_ft">
	                	<input type="text" class="weui_input tleft" name="birthAddr" id="birthAddr" value="${student.birthAddr }" placeholder="请选择户籍省市区" />
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">民族</label>
	                </div>
	                <div class="weui_cell_ft">
	                	<input type="text" class="weui_input tleft" name="nation" id="nation" value="${student.nation }" placeholder="请输入" />
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">国籍/地区</label>
	                </div>
	                <div class="weui_cell_ft">
	                	<input type="text" class="weui_input tleft" name="nationality" id="nationality" value="${student.nationality }" placeholder="请选择国籍/地区" />
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">户口性质</label>
	                </div>
	                <div class="weui_cell_ft">
	                	<input type="text" class="weui_input tleft" name="homeNature" id="homeNature" value="${student.homeNature }" placeholder="请选择户口性质" />
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">户口类型</label>
	                </div>
	                <div class="weui_cell_ft">
	                	<input type="text" class="weui_input tleft" name="studentPlaceType" id="studentPlaceType" value="${student.studentPlaceType }" placeholder="请选择户口类型" />
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">户口所在地</label>
	                </div>
	                <div class="weui_cell_ft">
	                	<input type="text" class="weui_input tleft" name="placeSSQ" id="placeSSQ" value="${student.placeSSQ }" placeholder="请选择户口所在地" />
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">户口所在地详细地址</label>
	                </div>
	                <div class="weui_cell_ft">
	                	<input type="text" class="weui_input tleft" name="placeDetail" id="placeDetail" value="${student.placeDetail }" placeholder="请选择户口所在地详细地址" />
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">现住址</label>
	                </div>
	                <div class="weui_cell_ft">
	                	<input type="text" class="weui_input tleft" name="homeAddr" id="homeAddr" value="${student.homeAddr }" placeholder="请输入省市区-详细地址" />
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">是否独生子女</label>
	                </div>
	                <div class="weui_cell_ft">
	                	<input type="text" class="weui_input tleft" name="onlyChild" id="onlyChild" value="${student.onlyChild }" placeholder="请选择" />
	                </div>
	            </div>
	            <div class="weui_cell hide">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">是否进城务工人员随迁子女</label>
	                </div>
	                <div class="weui_cell_ft">
	                	<input type="text" class="weui_input tleft" name="workFollowChild" id="workFollowChild" value="${student.workFollowChild }" readonly placeholder="请选择" />
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">借读类别</label>
	                </div>
	                <div class="weui_cell_ft place_input">
	                	<input type="text" class="weui_input tleft" name="place" id="place" value="${student.place }" readonly placeholder="请选择"/>
	                </div>
	            </div>
	            <div class="weui_cells_title f-red">注：政策性借读指非我市户口在我市有房产；父母其中一方是佛山户口；在我市有连续5年以上固定住址；有合法营业执照等证明。</div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd weui_cell_primary">
	                	<label class="weui_label">籍贯</label>
	                </div>
	                <div class="weui_cell_ft">
	                	<input type="text" class="weui_input tleft" name="nativePlace" id="nativePlace" value="${student.nativePlace }" placeholder="请选择" />
	                </div>
	            </div>
	        </div>
	        
	        <div class="weui_cells">
                <div class="weui_cell">
	                <div class="weui_cell_bd">
	                    <p>爸爸信息</p>
	                </div>
	            </div>
                <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>爸爸姓名</p>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" type="text" name="fatherName" id="fatherName" value="${student.fatherName }" placeholder="请输入爸爸姓名"/></div>
	            </div>
                <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>联系电话</p>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" type="number" name="fatherMobile" id="fatherMobile" value="${student.fatherMobile }" placeholder="请输入爸爸手机号码" /></div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>是否是监护人</p>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" name="fatherIsGuardian" id="fatherIsGuardian" value="${student.fatherIsGuardian }" placeholder="请选择"/></div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>户口所在地</p>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" name="fatherPlace" id="fatherPlace" value="${student.fatherPlace }" placeholder="请选择" /></div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>现住址</p>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" name="fatherHomeAddr" id="fatherHomeAddr" value="${student.fatherHomeAddr }" placeholder="请选择" /></div>
	            </div>
			</div>
	        <div class="weui_cells mb50">
                <div class="weui_cell">
	                <div class="weui_cell_bd">
	                    <p>妈妈信息</p>
	                </div>
	            </div>
                <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>妈妈姓名</p>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" type="text" name="motherName" id="motherName" value="${student.motherName }"  placeholder="请输入妈妈姓名"/></div>
	            </div>
                <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>联系号码</p>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" type="number" name="motherMobile" id="motherMobile" value="${student.motherMobile }"  placeholder="请输入妈妈手机号码"/></div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>是否是监护人</p>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" name="motherIsGuardian" id="motherIsGuardian" value="${student.motherIsGuardian }" placeholder="请选择"/></div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>户口所在地</p>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" name="motherPlace" id="motherPlace" value="${student.motherPlace }" placeholder="请选择" /></div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>现住址</p>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" name="motherHomeAddr" id="motherHomeAddr" value="${student.motherHomeAddr }" placeholder="请选择" /></div>
	            </div>
			</div>
			
		    <div class="weui_cells">
		    	<div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>车牌号码1</p>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" type="text" name="carNo1" id="carNo1" value="${student.carNo1 }" /></div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p>车牌号码2</p>
	                </div>
	                <div class="weui_cell_ft"><input class="weui_input tleft" type="text" name="carNo2" id="carNo2" value="${student.carNo2 }" /></div>
	            </div>
		    </div>
		    <div style="margin-bottom: 55px;"></div>
		</div>
	</div>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>

<script type="text/javascript">
	$(function() {
		init_workFollowChild();
		init_place();
		$("#birthday").datetimePicker({title:"选择日期",m:1});
		$("#sex").picker({
	        title: "请选择性别",
	        autoClose:true,
	        cols: [{textAlign: 'center',
	                 values: ['男', '女']
	               }]
        });
		$("#idNoType").picker({
	        title: "请选择身份证件类型",
	        autoClose:true,
	        cols: [{textAlign: 'center',
	                values: ['居民身份证','香港特区护照/身份证明','澳门特区护照/身份证明','台湾居民来往大陆通行证','境外永久居住证','护照','户口薄','其他']
	              }]
        });
		$("#nationality").picker({
			 title: "请选择国籍/地区",
		     autoClose:true,
		     cols: [{textAlign: 'center',
                 values: ["中国","香港","澳门","台湾","海外"]
               }]
		});
		$("#birthAddr").cityPicker({
	        title: "请选择户籍省市区"
	    });
		$("#placeSSQ").cityPicker({
	        title: "请选择户口所在地"
	    });
	    $("#homeNature").picker({
			 title: "请选择户口性质",
		     autoClose:true,
		     cols: [{textAlign: 'center',
                 values: ["农业","非农业"]
               }]
		});
	    $("#studentPlaceType").picker({
			 title: "请选择户口类型",
		     autoClose:true,
		     cols: [{textAlign: 'center',
                 values: ["广东省农村","广东省城镇","非广东省农村","非广东省城镇"]
               }]
		});
		$("#onlyChild").picker({
	        title: "请选择",
	        autoClose:true,
	        cols: [{textAlign: 'center',
                values: ['是','否']
              }]
        });
        $("#nativePlace").cityPicker({
	        title: "请选择省市区"
	    });
        $("#fatherIsGuardian").picker({
	        title: "请选择是否是监护人",
	        autoClose:true,
	        cols: [{textAlign: 'center',
                values: ['是','否']
              }]
        });
        $("#motherIsGuardian").picker({
	        title: "请选择是否是监护人",
	        autoClose:true,
	        cols: [{textAlign: 'center',
                values: ['是','否']
              }]
        });
        $("#fatherPlace").cityPicker({
	        title: "爸爸户口所在地"
	    });
        $("#motherPlace").cityPicker({
	        title: "妈妈户口所在地"
	    });
	    $("#fatherHomeAddr").cityPicker({
	        title: "爸爸现住址"
	    });
	    $("#motherHomeAddr").cityPicker({
	        title: "妈妈现住址"
	    });
	    $("#placeSSQ").change(function() {
	    	init_workFollowChild();
	    	init_place();
	    })
		$("#studentSubmit").click(function() {
			var sex = $("#sex").val();//性别
			if(sex.trim().length == 0) {
				$.toast("小孩性别为空", "forbidden");
				return;
			}
			var idNoType = $("#idNoType").val();//身份证件类别
			if(idNoType.trim().length == 0) {
				$.toast("请选择身份证件类型", "forbidden");
				return;
			}
			var idNo = $("#idNo").val();//身份证
			if(idNo.trim().length == 0) {
				$.toast("请输入身份证件号码", "forbidden");
				return;
			}
			var birthday = $("#birthday").val();//生日
			if(birthday.trim().length == 0) {
				$.toast("请选择出生日期", "forbidden");
				return;
			}
			var birthAddr = $("#birthAddr").val();//生日
			if(birthAddr.trim().length == 0) {
				$.toast("请选择出生地", "forbidden");
				return;
			}
			var nation = $("#nation").val();//民族
			if(nation.trim().length == 0) {
				$.toast("请输入民族", "forbidden");
				return;
			}
			var nationality = $("#nationality").val();//国籍/地区
			if(nationality.trim().length == 0) {
				$.toast("请选择国籍/地区", "forbidden");
				return;
			}
			var homeNature = $("#homeNature").val();//户口性质
			if(homeNature.trim().length == 0) {
				$.toast("请选择户口性质", "forbidden");
				return;
			}
			var studentPlaceType = $("#studentPlaceType").val();//户口类型
			if(studentPlaceType.trim().length == 0) {
				$.toast("请选择户口类型", "forbidden");
				return;
			}
			var placeSSQ = $("#placeSSQ").val();//户口所在地
			if(placeSSQ.trim().length == 0) {
				$.toast("请选择户口所在地", "forbidden");
				return;
			}
			var placeDetail = $("#placeDetail").val();//户口详细地址
			if(placeDetail.trim().length == 0) {
				$.toast("请输入户口详细地址", "forbidden");
				return;
			}
			var homeAddr = $("#homeAddr").val();//现住址
			if(homeAddr.trim().length == 0) {
				$.toast("请选择现住址", "forbidden");
				return;
			}
			var onlyChild = $("#onlyChild").val();//是否独生子女
			if(onlyChild.trim().length == 0) {
				$.toast("请选择是否独生子女", "forbidden");
				return;
			}
			var workFollowChild = $("#workFollowChild").val();//是否进城务工人员随迁子女
			if(workFollowChild.trim().length == 0) {
				$.toast("请选择是否进城务工人员随迁子女", "forbidden");
				return;
			}
			var place = $("#place").val();//借读类别
			if(place.trim().length == 0) {
				$.toast("请选择借读类别", "forbidden");
				return;
			}
			var nativePlace = $("#nativePlace").val();//籍贯
			if(nativePlace.trim().length == 0) {
				$.toast("请选择籍贯", "forbidden");
				return;
			}
			var fatherName = $("#fatherName").val();
			var motherName = $("#motherName").val();
			if(fatherName.trim().length == 0 && motherName.trim().length == 0) {
				$.toast("请输入至少一个家长的姓名", "forbidden");
				return;
			}
			var fatherMobile = $("#fatherMobile").val();
			if(fatherMobile.length > 0 && !checkPhone(fatherMobile)) {
				$.toast("爸爸手机号码格式不正确", "forbidden");
				return;
			}
			var motherMobile = $("#motherMobile").val();
			if(motherMobile.length > 0 && !checkPhone(motherMobile)) {
				$.toast("妈妈手机号码格式不正确", "forbidden");
				return;
			}
			if(fatherMobile.trim().length == 0 && motherMobile.trim().length == 0) {
				$.toast("请输入至少一个家长的手机号码", "forbidden");
				return;
			}
			if(fatherName.trim().length == 0 && motherMobile.trim().length == 0) {
				$.toast("请输入至少一个家长的姓名", "forbidden");
				return;
			}
			var fatherIsGuardian = $("#fatherIsGuardian").val();//是否是监护人
			var motherIsGuardian = $("#motherIsGuardian").val();//是否是监护人
			if(fatherIsGuardian.trim().length == 0 && motherIsGuardian.trim().length == 0) {
				$.toast("请选择一个家长设为监护人", "forbidden");
				return;
			}
			var fatherPlace = $("#fatherPlace").val();//户口所在地
			var motherPlace = $("#motherPlace").val();//户口所在地
			if(fatherPlace.trim().length == 0 && motherPlace.trim().length == 0) {
				$.toast("请选择一个家长的户口所在地", "forbidden");
				return;
			}
			var fatherHomeAddr = $("#fatherHomeAddr").val();//现住址
			var motherHomeAddr = $("#motherHomeAddr").val();//现住址
			if(motherHomeAddr.trim().length == 0 && fatherHomeAddr.trim().length == 0) {
				$.toast("请选择一个家长的现住址", "forbidden");
				return;
			}
			$.ajax({
				url : basePath + "/ls/students/manage/info/update",
		 		type : "post",
		 		dataType : "json",
		 		data: {
		 			id: $("#id").val(),
		 			sex: sex,
					idNoType: idNoType,
					idNo: idNo,		
					birthday: birthday,		
					birthAddr: birthAddr,
					nation: nation,			
					nationality: nationality,	
					homeNature: homeNature,			
					studentPlaceType: studentPlaceType,	
					placeSSQ: placeSSQ,			
					placeDetail: placeDetail,			
					homeAddr: homeAddr,		
					onlyChild: onlyChild,	
					workFollowChild: workFollowChild,
					place: place,		
					nativePlace: nativePlace,	
					fatherName: fatherName,			
					fatherMobile: fatherMobile,			
					fatherIsGuardian: fatherIsGuardian,
					fatherPlace: fatherPlace,		
					fatherHomeAddr: fatherHomeAddr,		
					motherName: motherName,			
					motherMobile: motherMobile,		
					motherIsGuardian: motherIsGuardian,		
					motherPlace: motherPlace,		
					motherHomeAddr: motherHomeAddr,
					carNo1: $("#carNo1").val(),
		 			carNo2: $("#carNo2").val()
		 		},
		 		async : false,
		 		success : function(data) {
		 			if(data.code == '000') {
		 				$.toast("提交成功");
		 				return;
		 			}
		 			$.toast(data.msg, "cancel");
		 		}, error:function(){
		 			$.toast("提交异常", "cancel");
	      		}
	        });
		})
	})
	function init_workFollowChild() {
		var placeSSQ = $("#placeSSQ").val();
		if(placeSSQ.trim().length == 0) return;
    	if(placeSSQ.indexOf("佛山") != -1) {
    		$("#workFollowChild").val("否");
    	}else {
    		$("#workFollowChild").val("是");
    	}
	}
	function init_place() {
		var placeSSQ = $("#placeSSQ").val();
    	if(placeSSQ.length == 0) return;
    	if(placeSSQ.indexOf("佛山") == -1) {
    		$(".place_Input").html('<input type="text" class="weui_input tleft" name="place" id="place" placeholder="请选择" readonly="readonly"/>');
    		$("#place").picker({
		        title: "请选择户口类型",
			    autoClose:true,
			    cols: [{textAlign: 'center',
	                values: ["政策性借读","非政策性借读"]
	              }]
		   	});
    	}else {
    		var place = $("#place").val();
    		if(place.length == 0) {
    			$("#place").val(placeSSQ.substring(placeSSQ.lastIndexOf(" ")+1, placeSSQ.length));
    		}
    	}
	}
</script>
</body>
</html>